package com.wyh.controller.groupfour.admin;

import com.wyh.common.exception.ResourceNotFoundException;
import com.wyh.common.result.Result;
import com.wyh.domain.vo.gruopfour.chargeVO.RefundVO;
import com.wyh.domain.vo.gruopfour.threemeterVO.PageResult;
import com.wyh.service.appservice.ChargeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.wyh.common.enums.FindResourceEnum.RENTED;
import static com.wyh.common.enums.ResultCodeEnum.RESOURCE_NOT_ERROR;

//统一收费
@RestController
@Api(tags = "收费和管理")
@Slf4j
public class ChargeController {

    @Autowired
    private ChargeService chargeService;

    @GetMapping("/refund")
    @ApiOperation("退款列表")
    public Result<PageResult<RefundVO>> refund(@RequestParam(value = "state", defaultValue = "1") int state,
                                         @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {

        List<Integer> ids = chargeService.getAllResourceIds(RENTED.getCode());
        log.info("退款列表中资源id:{}",ids);
        if (ids == null || ids.isEmpty()) {
            throw new ResourceNotFoundException(RESOURCE_NOT_ERROR.getCode(),RESOURCE_NOT_ERROR.getMsg());
        }
        PageResult<RefundVO> refund = chargeService.getRefund(state, pageNum, pageSize, ids);
        return Result.success(refund);

    }

}
